﻿@model Ducu.SRV.ViewModel.User._CreditModel
@{object userId = ViewContext.RouteData.Values["userId"];}
<div class="well" style=" background-color: white;">
    <img src="/Image/applause.png" title="鼓掌" class="pull-right" style="display:none;" id="applause" />
    <div class="lead">
        <label class="text-info">全部积分：</label>
        <a href="/User/Credits/@userId"><span class="text-primary" id="credit-show" style="margin-left: 10px; opacity: 0.6; ">0</span></a>
    </div>
    @if (Model.All > 0)
    {
        <hr />
        <div id="latest-gain">
            <label class="text-info">最后一次是在：</label>
            @if (Model.LatestGainDaysBefore > 0)
            {
                <span>@Model.LatestGainDaysBefore</span><text> 天前</text>

            }
            else
            {
                <span>今天</span>
            }
            ，获得<span class="text-primary" id="credit-yesterday" style="margin-left: 10px; opacity: 0.6; ">@Model.LatestGainNumber </span>分
        </div>
    }
</div>
<script>
    var allCredits = @Model.All,
        handler;
    var value = 0;
    $(document).ready(function () {
        handler = setInterval("showAllCredits()", 30);
    })

    function showAllCredits() {
        showCredits($("#credit-show"));
    }

    function showCredits(element) {
        if (value < allCredits) {
            addValue(allCredits);
            element.text(value);
        } else {
            for (var i = 0; i < 4; i++) {
                if (i % 2 == 0) {
                    element.animate({ opacity: '0.2' }, "5");
                } else {
                    element.animate({ opacity: '1' }, "5");
                }
            }
            $("#applause").show();
            clearInterval(handler);
        }
    }

    function addValue(credit) {
        divisor = 1;
        for (var i = 1; i < String(value).length; i++) {
            divisor = 10 * divisor;
        }
        if (divisor > 1) {
            if (value + divisor < (allCredits / divisor) * divisor) {
                value += divisor;
            } else {
                value += allCredits % divisor;
            }
        }else{
            value +=1;
        }
    }
</script>